/**
 * JCharsetChooser.java
 * @author Daniel Liu
 * Create: 2007-1-4 ����03:43:09
 */
package org.lex.swing.widgets;

import java.awt.Window;
import java.nio.charset.Charset;

import javax.swing.ListSelectionModel;

import org.lex.awt.Location;
import org.lex.swing.Option;


public class JCharsetChooser {
	/*
	 * enum: SINGLE_SELECTION ListSelectionModel.SINGLE_SELECTION
	 * SINGLE_INTERVAL_SELECTION ListSelectionModel.SINGLE_INTERVAL_SELECTION
	 * MULTIPLE_INTERVAL_SELECTION
	 * ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
	 */
	public static final int SINGLE_SELECTION = ListSelectionModel.SINGLE_SELECTION;
	public static final int SINGLE_INTERVAL_SELECTION = ListSelectionModel.SINGLE_INTERVAL_SELECTION;
	public static final int MULTIPLE_INTERVAL_SELECTION = ListSelectionModel.MULTIPLE_INTERVAL_SELECTION;

	/**
	 * @return Charset[],���Ա�֤����ֵ���� null
	 */
	public static Charset[] showDialog(Window owner, int mode) {
		CharsetDialog dialog = new CharsetDialog(owner);
		dialog.setModal(true);
		dialog.setSelectionMode(mode);
		if (null != owner)
			Location.moveToParentCenter(owner, dialog);
		dialog.setVisible(true);
		Charset[] charset = new Charset[0];
		Option selection = dialog.getSelection();
		if (selection.isYesOption()) {
			charset = dialog.getSelectedCharsets();
		}
		dialog = null;
		return charset;
	}

	/**
	 * @return Charset������ null
	 */
	public static Charset showSingleSelection(Window owner) {
		Charset charset = null;
		Charset[] cs = showDialog(owner, SINGLE_SELECTION);
		if (0 != cs.length)
			charset = cs[0];
		return charset;
	}

	public static Charset[] showMultipleSelection(Window owner) {
		return showDialog(owner, MULTIPLE_INTERVAL_SELECTION);
	}
}
